package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.PrinterService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.PrinterAddVO;
import com.junzhiit.nengji.cms.web.vo.PrinterEditVO;
import com.junzhiit.nengji.cms.web.vo.PrinterVO;
import com.junzhiit.nengji.cms.web.vo.PrinterVoiceVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

@RestController
@RequestMapping("/printer")
public class PrinterController extends BaseController{
	
	@Autowired
	private PrinterService printerService;
	
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findPageAll(PrinterVO printerVO,DataTablesParamVO dtp){
		return printerService.findPageAll(printerVO,dtp);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		return printerService.findById(id);
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(PrinterAddVO printerAddVO){
		AssertUtil.notBlank(printerAddVO.getName(), "name is required");
		AssertUtil.notNull(printerAddVO.getPrinterType(), "printerType is required");
		AssertUtil.notNull(printerAddVO.getPaperWidthType(), "paperWidthType is required");
		AssertUtil.notBlank(printerAddVO.getDeviceKey(), "deviceKey is required");
		AssertUtil.notBlank(printerAddVO.getDeviceNumber(), "deviceNumber is required");
		AssertUtil.notNull(printerAddVO.getNumber(), "number is required");
		AssertUtil.notBlank(printerAddVO.getPrinterTemplateId(), "printerTemplateId() is required");
		return printerService.add(printerAddVO);
	}
	
	
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResultVO edit(@PathVariable String id,PrinterEditVO printerEditVO){
		AssertUtil.notBlank(id, "id is required");
		AssertUtil.notBlank(printerEditVO.getName(), "name is required");
		AssertUtil.notNull(printerEditVO.getPrinterType(), "printerType is required");
		AssertUtil.notNull(printerEditVO.getPaperWidthType(), "paperWidthType is required");
		AssertUtil.notBlank(printerEditVO.getDeviceKey(), "deviceKey is required");
		AssertUtil.notBlank(printerEditVO.getDeviceNumber(), "deviceNumber is required");
		AssertUtil.notNull(printerEditVO.getNumber(), "number is required");
		AssertUtil.notBlank(printerEditVO.getPrinterTemplateId(), "printerTemplateId() is required");
		AssertUtil.notNull(printerEditVO.getType(), "type is required");
		return printerService.edit(id,printerEditVO);
	}
	
	@RequestMapping(value="/print",method=RequestMethod.POST)
	public ResultVO print(PrinterAddVO printerAddVO){
		AssertUtil.notBlank(printerAddVO.getName(), "name is required");
		AssertUtil.notNull(printerAddVO.getPrinterType(), "printerType is required");
		AssertUtil.notNull(printerAddVO.getPaperWidthType(), "paperWidthType is required");
		AssertUtil.notBlank(printerAddVO.getDeviceKey(), "deviceKey is required");
		AssertUtil.notBlank(printerAddVO.getDeviceNumber(), "deviceNumber is required");
		AssertUtil.notNull(printerAddVO.getNumber(), "number is required");
		AssertUtil.notBlank(printerAddVO.getPrinterTemplateId(), "printerTemplateId() is required");
		AssertUtil.notNull(printerAddVO.getType(), "type is required");
		return printerService.print(printerAddVO);
	}
	
	@RequestMapping(value="/del/{id}",method=RequestMethod.PUT)
	public ResultVO updateToDelete(@PathVariable String id){
		return printerService.updateToDelete(id);
	}
	
	@RequestMapping(value="/shutdown/{id}",method=RequestMethod.POST)
	public ResultVO shutdown(@PathVariable String id){
		return printerService.shutdown(id);
	}
	
	@RequestMapping(value="/restart/{id}",method=RequestMethod.POST)
	public ResultVO restart(@PathVariable String id){
		return printerService.restart(id);
	}
	
	@RequestMapping(value="/sound/{id}",method=RequestMethod.POST)
	public ResultVO setSound(@PathVariable String id,PrinterVoiceVO printerVoiceVO ){
		AssertUtil.notNull(printerVoiceVO.getSound(), "hint voice is required");
		AssertUtil.notNull(printerVoiceVO.getSoundType(), "isOpenHint voice is required");
		return printerService.setSound(id,printerVoiceVO);
	}

	@RequestMapping(value="/voice/{id}",method=RequestMethod.POST)
	public ResultVO setVoice(@PathVariable String id,PrinterVoiceVO printerVoiceVO){
		AssertUtil.notNull(printerVoiceVO.getVoice(), "hint voice is required");
		AssertUtil.notNull(printerVoiceVO.getSoundType(), "isOpenHint voice is required");
		return printerService.setVoice(id,printerVoiceVO);
	} 
	
}
